import sys
from PyQt6.QtWidgets import QApplication, QTreeWidget, QTreeWidgetItem


def main():
    app = QApplication(sys.argv)

    tree = QTreeWidget()
    tree.setColumnCount(2)
    tree.setHeaderLabels(['Key', 'Value'])

    # 创建根节点
    root = QTreeWidgetItem(tree)
    root.setText(0, 'Root')
    root.setText(1, 'root_value')

    # 添加子节点
    child1 = QTreeWidgetItem(root)
    child1.setText(0, 'Child 1')
    child1.setText(1, 'child1_value')

    child2 = QTreeWidgetItem(root)
    child2.setText(0, 'Child 2')
    child2.setText(1, 'child2_value')

    # 添加子节点的子节点
    grandchild = QTreeWidgetItem(child1)
    grandchild.setText(0, 'Grandchild')
    grandchild.setText(1, 'grandchild_value')

    # 展示树
    tree.show()

    sys.exit(app.exec())


if __name__ == '__main__':
    main()
